/* 1422. 分割字符串的最大得分 */
/**
 * @param {string} s
 * @return {number}
 */
/* 枚举每一个字符 */
var maxScore = function (s) {
	const n = s.length
	let left = 1
	let ans = 0
	while (left < n) {
		const leftStr = s.slice(0, left)
		const rightStr = s.slice(left)
		ans = Math.max(ans, helper(leftStr, '0') + helper(rightStr, '1'))
		left++
	}
	return ans
}
const helper = (str, target) => {
	let res = 0
	for (let i = 0; i < str.length; i++) {
		if (str[i] === target) {
			res++
		}
	}
	return res
}
/* 
    两次遍历 在遍历的过程中，右边减少一个左边添加一个
*/
var maxScore = function (s) {
	let score = 0
	const n = s.length
	if (s[0] === '0') {
		score++
	}
	for (let i = 1; i < n; i++) {
		if (s[i] === '1') {
			score++
		}
	}
	let ans = score
	for (let i = 1; i < n - 1; i++) {
		if (s[i] === '0') {
			score++
		} else {
			score--
		}
		ans = Math.max(ans, score)
	}
	return ans
}
const ans = maxScore('000001')
console.log('maxScore :>>', ans)
